<%-- 
    Document   : Register
    Created on : Jun 12, 2012, 12:13:32 PM
    Author     : Trungnm
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Register</title>
        <script type="text/javascript">
            var Re_Email = /^(\w+[\-\.])*\w+@(\w+\.)+[A-Za-z]+$/;
            var Re_Password = /^[A-Za-z\d\S]{6,16}$/;
            var Re_CPassword = /^[A-Za-z\d\S]{6,16}$/;
            var Re_Username = /^\w+$/;
            function validate(form){
                var email = form.Email.value;
                var password = form.pwd.value;
                var Cpassword = form.ConfirmPwd.value;
                var username = form.username.value;
                var errors = [];
                if(!Re_Email.test(email)){
                    errors[errors.length] = "Please enter a valid email address!!!";
                }
                if(!Re_Password.test(password)){
                    errors[errors.length] = "Please enter a valid password!!!";
                }
                if(!Re_Username.test(username)){
                    errors[errors.length] = "Please enter a valid username!!!";
                }
                if(Cpassword != password){
                    errors[errors.length] = "Password and ConfirmPassword are not match!!!";
                }
                if(errors.length>0){
                    reportErrors(errors);
                    return false;
                }
                return true;
            }
            
            function reportErrors(errors){
                var msg = "There were some problems...\n";
                for( var i = 0; i<errors.length; i++){
                    var numErrors = i + 1;
                    msg += "\n" + numErrors + ". " + errors[i];
                }
                alert(msg);
            }
        </script>
    </head>
    <body>
        <form method="post" action="Login" onsubmit="return validate(this)">
            <table border="5" style="background-color: lightsteelblue;" align="center" width="300" height="300">
                <tr>
                    <td>
                        <h1 align="center">Register</h1>
                        <div align="right">
                            Username* <input type="text" name="username" value="" style="background-color: cornsilk;"><br/><br/>
                            Password* (6 to 16 letters)<br/> <input type="password" name="pwd" value="" style="background-color: cornsilk;"><br/><br/>
                            Confirm Password* <input type="password" name="ConfirmPwd" value="" style="background-color: cornsilk;"><br/><br/>
                            Email* <input type="text" name="Email" value="" style="background-color: cornsilk;"><br/><br/>
                        </div>
                        <div align="center">
                            <input type="submit" value="Create" name="create">
                            <input type="reset" value="Reset" name="reset"><br/>
                            <br/>I have an account <a href ="loginPage.jsp">Login</a> here
                        </div>
                    </td>
                </tr>
            </table>
        </form>
    </body>
</html>
